/*
* This file is a part of the open-eBackup project.
* This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
* If a copy of the MPL was not distributed with this file, You can obtain one at
* http://mozilla.org/MPL/2.0/.
*
* Copyright (c) [2024] Huawei Technologies Co.,Ltd.
*
* THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
* EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
* MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
*/
#include "nas_share/common/HetroCommonService.h"
#include "utils/PluginUtilities.h"
#include "system/System.hpp"
#include "client/ClientInvoke.h"
#include "utils/CertMgr.h"

#include "gtest/gtest.h"
#include "mockcpp/mockcpp.hpp"

using namespace PluginUtils;
using namespace std;
using namespace Module;

namespace {
    constexpr auto MODULE = "HetroCommonService";
}

namespace TEST_Module{
    class HetroCommonServiceImpl : public HetroCommonService {
    public:
        HetroCommonServiceImpl();
        ~HetroCommonServiceImpl() override;
        int PrerequisiteJob() override;
        int GenerateSubJob() override;
        int ExecuteSubJob() override;
        int PostJob() override;       
    };
    HetroCommonServiceImpl::HetroCommonServiceImpl() {}
    HetroCommonServiceImpl::~HetroCommonServiceImpl() {}
    int HetroCommonServiceImpl::PrerequisiteJob() {}
    int HetroCommonServiceImpl::GenerateSubJob() {}
    int HetroCommonServiceImpl::ExecuteSubJob() {}
    int HetroCommonServiceImpl::PostJob() {} 
}

class HetroCommonServiceTest : public testing::Test {
public:
    void SetUp();
    void TearDown();
    static void SetUpTestCase();
    static void TearDownTestCase();
    std::shared_ptr<TEST_Module::HetroCommonServiceImpl> m_ins;
};

static int StubFunction_Succ()
{
    return 0;
}

void HetroCommonServiceTest::SetUp()
{
    MOCKER_CPP(&sleep)
            .stubs()
            .will(invoke(StubFunction_Succ));
    m_ins = make_shared<TEST_Module::HetroCommonServiceImpl>();
}

void HetroCommonServiceTest::TearDown()
{
    GlobalMockObject::verify(); // 校验mock规范并清除mock规范
}

void HetroCommonServiceTest::SetUpTestCase()
{}

void HetroCommonServiceTest::TearDownTestCase()
{}

/*
 * 用例名称：checkFilePathAndGetSrcFileList
 * 前置条件：无
 * check点：检查文件路径并获得源文件列表
 **/
TEST_F(HetroCommonServiceTest, checkFilePathAndGetSrcFileList)
{
    MOCKER_CPP(&PluginUtils::PathExistMandate)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&PluginUtils::GetFileListInDirectory)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    std::string srcDir;
    std::string dstDir;
    std::vector<std::string> srcFileList;
    EXPECT_EQ(m_ins->checkFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList), false);
    EXPECT_EQ(m_ins->checkFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList), false);
    EXPECT_EQ(m_ins->checkFilePathAndGetSrcFileList(srcDir, dstDir, srcFileList), true);      
}

/*
 * 用例名称：IsValidCtrlFile
 * 前置条件：无
 * check点：判断控制文件是否有效
 **/
TEST_F(HetroCommonServiceTest, IsValidCtrlFile)
{
    uint32_t subTaskType = 0;  
    std::string ctrlFileFullPath = "txt.tmp";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), false);
    subTaskType = SUBJOB_TYPE_DATACOPY_COPY_PHASE;
    ctrlFileFullPath = "/control_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), true);
    subTaskType = SUBJOB_TYPE_DATACOPY_DELETE_PHASE;
    ctrlFileFullPath = "/delete_control_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), true);
    subTaskType = SUBJOB_TYPE_DATACOPY_HARDLINK_PHASE;
    ctrlFileFullPath = "/hardlink_control_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), true);
    subTaskType = SUBJOB_TYPE_DATACOPY_DIRMTIME_PHASE;
    ctrlFileFullPath = "/mtime_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), true);
    subTaskType = SUBJOB_TYPE_ANY;
    ctrlFileFullPath = "/mtime_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), false);
    subTaskType = -1;
    ctrlFileFullPath = "/delete_control_";
    EXPECT_EQ(m_ins->IsValidCtrlFile(subTaskType, ctrlFileFullPath), false);      
}

/*
 * 用例名称：GetSubJobTypeByFileName
 * 前置条件：无
 * check点：获取子任务类型
 **/
TEST_F(HetroCommonServiceTest, GetSubJobTypeByFileName)
{
    std::string fileName = "hardlink";
    std::string subTaskName;
    uint32_t subTaskType;
    uint32_t subTaskPrio;
    EXPECT_EQ(m_ins->GetSubJobTypeByFileName(fileName, subTaskName, subTaskType, subTaskPrio), true);
    fileName = "mtime";
    EXPECT_EQ(m_ins->GetSubJobTypeByFileName(fileName, subTaskName, subTaskType, subTaskPrio), true);
    fileName = "delete";
    EXPECT_EQ(m_ins->GetSubJobTypeByFileName(fileName, subTaskName, subTaskType, subTaskPrio), true);
    fileName = "xxx";
    EXPECT_EQ(m_ins->GetSubJobTypeByFileName(fileName, subTaskName, subTaskType, subTaskPrio), true);  

    SubJob subJob;
    std::string jobId;
    std::string ctrlFile;
    // uint32_t subTaskType;
    std::string ext;
    EXPECT_EQ(m_ins->InitSubTask(subJob, jobId, ctrlFile, subTaskType, ext), true);       
}

TEST_F(HetroCommonServiceTest, CreateSubTask)
{
    std::vector<SubJob> subJobList {};
    std::vector<std::string> ctrlFileList {};
    EXPECT_EQ(m_ins->CreateSubTask(subJobList, ctrlFileList), Module::SUCCESS);
}

/*
 * 用例名称：GetSharedResources
 * 前置条件：无
 * check点：获取共享资源
 **/
TEST_F(HetroCommonServiceTest, GetSharedResources)
{
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::GetGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::GetScanStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::GetBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    std::string jobId;
    HetroNativeGeneral generalInfo;
    HetroNativeScanStatistics scanStats;
    HetroNativeBackupStats backupStats;
    EXPECT_EQ(m_ins->GetSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->GetSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->GetSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->GetSharedResources(jobId, generalInfo, scanStats, backupStats), true);      
}

/*
 * 用例名称：DeleteSharedResources
 * 前置条件：无
 * check点：删除共享资源
 **/
TEST_F(HetroCommonServiceTest, DeleteSharedResources)
{
//     MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteGeneralResource)
//             .stubs()
//             .will(returnValue(false))
//             .then(returnValue(true));
//     MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteScanStatsResource)
//             .stubs()
//             .will(returnValue(false))
//             .then(returnValue(true));
//     MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteBackupStatsResource)
//             .stubs()
//             .will(returnValue(false))
//             .then(returnValue(true));
//     MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::UpdateGlobalScanRedoList)
//             .stubs()
//             .will(returnValue(false))
//             .then(returnValue(true));
//     std::string jobId;
//     EXPECT_EQ(m_ins->DeleteSharedResources(jobId), true);
//     EXPECT_EQ(m_ins->DeleteSharedResources(jobId), true);
//     EXPECT_EQ(m_ins->DeleteSharedResources(jobId), true);
//     EXPECT_EQ(m_ins->DeleteSharedResources(jobId), true); 
//     EXPECT_EQ(m_ins->DeleteSharedResources(jobId), true);      
}

/*
 * 用例名称：ChangeHostnameToIp
 * 前置条件：无
 * check点：更改主机名
 **/
TEST_F(HetroCommonServiceTest, ChangeHostnameToIp)
{
    std::string hostname = "";
    std::string protocol = "";
    EXPECT_EQ(m_ins->ChangeHostnameToIp(hostname, protocol), -1);
    hostname = "[";
    EXPECT_EQ(m_ins->ChangeHostnameToIp(hostname, protocol), 0);     
}

/*
 * 用例名称：CheckIpPortConnection
 * 前置条件：无
 * check点：检查Ip端口连接
 **/
TEST_F(HetroCommonServiceTest, CheckIpPortConnection)
{
    MOCKER_CPP(&Module::runShellCmdWithOutput)
            .stubs()
            .will(returnValue(6))
            .then(returnValue(0));
    std::string ip;
    std::string port;
    EXPECT_EQ(m_ins->CheckIpPortConnection(ip, port), true);
    EXPECT_EQ(m_ins->GetFilterType("INCLUDE"), FILTER_TYPE::INCLUDE);
    EXPECT_EQ(m_ins->GetFilterType("EXCLUDE"), FILTER_TYPE::EXCLUDE);
    EXPECT_EQ(m_ins->GetFilterType("xxx"), FILTER_TYPE::DISABLED);
    string versionString = SMB_VERSION_3_1_1;
    EXPECT_EQ(m_ins->ConvertStringToSmbVersion(versionString), Module::SmbVersion::VERSION0311); 
    versionString = SMB_VERSION_3_02;
    EXPECT_EQ(m_ins->ConvertStringToSmbVersion(versionString), Module::SmbVersion::VERSION0302); 
    versionString = SMB_VERSION_3_0;
    EXPECT_EQ(m_ins->ConvertStringToSmbVersion(versionString), Module::SmbVersion::VERSION0300); 
    versionString = SMB_VERSION_2_1;
    EXPECT_EQ(m_ins->ConvertStringToSmbVersion(versionString), Module::SmbVersion::VERSION0210); 
    versionString = SMB_VERSION_2_0;
    EXPECT_EQ(m_ins->ConvertStringToSmbVersion(versionString), Module::SmbVersion::VERSION0202);     
}

/*
 * 用例名称：ConvertSmbVersionToString
 * 前置条件：无
 * check点：检查Ip端口连接
 **/
TEST_F(HetroCommonServiceTest, ConvertSmbVersionToString)
{
    string versionString = SMB_VERSION_3_1_1;
    EXPECT_EQ(m_ins->ConvertSmbVersionToString(Module::SmbVersion::VERSION0311), versionString); 
    versionString = SMB_VERSION_3_02;
    EXPECT_EQ(m_ins->ConvertSmbVersionToString(Module::SmbVersion::VERSION0302), versionString); 
    versionString = SMB_VERSION_3_0;
    EXPECT_EQ(m_ins->ConvertSmbVersionToString(Module::SmbVersion::VERSION0300), versionString); 
    versionString = SMB_VERSION_2_1;
    EXPECT_EQ(m_ins->ConvertSmbVersionToString(Module::SmbVersion::VERSION0210), versionString); 
    versionString = SMB_VERSION_2_0;
    EXPECT_EQ(m_ins->ConvertSmbVersionToString(Module::SmbVersion::VERSION0202), versionString);     
}

/*
 * 用例名称：ReportJobDetails
 * 前置条件：无
 * check点：上报工作内容
 **/
static void StubReportJobDetails1(ActionResult& returnValue, const SubJobDetails& jobInfo) 
{
    returnValue.code = -1;
}
static void StubReportJobDetails2(ActionResult& returnValue, const SubJobDetails& jobInfo) 
{
    returnValue.code = 0;
}
TEST_F(HetroCommonServiceTest, ReportJobDetails)
{
    MOCKER_CPP(JobService::ReportJobDetails)
            .stubs()
            .will(ignoreReturnValue());    
    LogDetail logDetail;
    AppProtect::JobLogLevel::type jobLogLevel {};
    logDetail.level = jobLogLevel;
    logDetail.description = "xxx";
    SubJobDetails jobInfo;
    jobInfo.logDetail.push_back(logDetail);
    EXPECT_EQ(m_ins->ReportJobDetails(jobInfo), true);
}

/*
 * 用例名称：QueryResource
 * 前置条件：无
 * check点：查询资源
 **/
TEST_F(HetroCommonServiceTest, QueryResource)
{
    MOCKER_CPP(ShareResource::QueryResource)
            .stubs()
            .will(throws(AppProtectFrameworkException()))
            .then(ignoreReturnValue());            
    std::string key;
    AppProtect::ResourceStatus ret;
    EXPECT_EQ(m_ins->QueryResource(key, ret), true);
    EXPECT_EQ(m_ins->QueryResource(key, ret), true);
}

/*
 * 用例名称：GetScanStatsResource
 * 前置条件：无
 * check点：查询资源
 **/
TEST_F(HetroCommonServiceTest, GetScanStatsResource)
{
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::QueryResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true))
            .then(returnValue(false))
            .then(returnValue(true));             
    std::string key;
    HetroNativeScanStatistics scanStats;
    EXPECT_EQ(m_ins->GetScanStatsResource(key, scanStats), false);
    EXPECT_EQ(m_ins->GetScanStatsResource(key, scanStats), false);
    HetroNativeBackupStats backupStats;
    EXPECT_EQ(m_ins->GetBackupStatsResource(key, backupStats), false);
    EXPECT_EQ(m_ins->GetBackupStatsResource(key, backupStats), false);
    HetroNativeGeneral generalInfo;
    EXPECT_EQ(m_ins->GetGeneralResource(key, generalInfo), false);
    EXPECT_EQ(m_ins->GetGeneralResource(key, generalInfo), false);
}

/*
 * 用例名称：CleanKrbFilesForCifs
 * 前置条件：无
 * check点：创建资源
 **/
TEST_F(HetroCommonServiceTest, CleanKrbFilesForCifs)
{                  
    std::string jobId;
    EXPECT_NO_THROW(m_ins->CleanKrbFilesForCifs(jobId));
}

/*
 * 用例名称：CreateSharedResources
 * 前置条件：无
 * check点：创建资源
 **/
TEST_F(HetroCommonServiceTest, CreateSharedResources)
{           
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::CreateGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::CreateScanStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteGeneralResource)
            .stubs()
            .will(ignoreReturnValue());
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::CreateBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteScanStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));    
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteGeneralResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteScanStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::DeleteBackupStatsResource)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    std::string jobId;
    HetroNativeGeneral generalInfo;
    HetroNativeScanStatistics scanStats;
    HetroNativeBackupStats backupStats;
    EXPECT_EQ(m_ins->CreateSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->CreateSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->CreateSharedResources(jobId, generalInfo, scanStats, backupStats), false);
    EXPECT_EQ(m_ins->CreateSharedResources(jobId, generalInfo, scanStats, backupStats), true);
    EXPECT_EQ(m_ins->CreateSharedResources(jobId, generalInfo, scanStats, backupStats), true);
}

/*
 * 用例名称：CheckDataFsMount
 * 前置条件：无
 * check点：检查挂载数据
 **/
TEST_F(HetroCommonServiceTest, CheckDataFsMount)
{   
    MOCKER_CPP(&PluginUtils::CheckNfsAccessibility)
            .stubs()
            .will(returnValue(-1))
            .then(returnValue(0)); 
    std::string proto;
    std::string protoVersion;
    StorageRepository m_dataFs;
    m_dataFs.remotePath = "xxx";
    std::string m_dataFsSvcIp;
    ProtectedNasShare m_nasShare;
    EXPECT_EQ(m_ins->CheckDataFsMount(proto, protoVersion, m_dataFs, m_dataFsSvcIp, m_nasShare), false);
    EXPECT_EQ(m_ins->CheckDataFsMount(proto, protoVersion, m_dataFs, m_dataFsSvcIp, m_nasShare), true);
}

/*
 * 用例名称：RemoveCertification
 * 前置条件：无
 * check点：移除证明
 **/
TEST_F(HetroCommonServiceTest, RemoveCertification)
{   
    MOCKER_CPP(&CertMgr::InitInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&CertMgr::IsVerify)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&CertMgr::RemoveCertAndRevocationListFromDisk)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    AppProtect::ApplicationEnvironment protectEnv;
    EXPECT_EQ(m_ins->RemoveCertification(protectEnv), false);
    EXPECT_EQ(m_ins->RemoveCertification(protectEnv), true);
    EXPECT_EQ(m_ins->RemoveCertification(protectEnv), false);
    EXPECT_EQ(m_ins->RemoveCertification(protectEnv), true);
}

/*
 * 用例名称：CertVerifyMgr
 * 前置条件：无
 * check点：证明验证
 **/
TEST_F(HetroCommonServiceTest, CertVerifyMgr)
{   
    MOCKER_CPP(&CertMgr::InitInfo)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&CertMgr::IsVerify)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true)); 
    MOCKER_CPP(&CertMgr::FlushCertificationToDisk)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    string str = "xxx";
    MOCKER_CPP(&CertMgr::GetCertPath)
            .stubs()
            .will(returnValue(str));
    MOCKER_CPP(&CertMgr::IncludeRevocationList)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&CertMgr::FlushRevocationListToDisk)
            .stubs()
            .will(returnValue(false))
            .then(returnValue(true));
    MOCKER_CPP(&CertMgr::GetCrlPath)
            .stubs()
            .will(returnValue(str));
    AppProtect::ApplicationEnvironment protectEnv;
    ProtectedNasHost nasHost;
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), false);
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), true);
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), false);
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), true);
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), false);
    EXPECT_EQ(m_ins->CertVerifyMgr(protectEnv, nasHost), true);
}

/*
 * 用例名称：GetProtocolType
 * 前置条件：无
 * check点：获取协议类型
 **/
TEST_F(HetroCommonServiceTest, GetProtocolType)
{    
    std::string protocol = NAS_PROTOCOL_TYPE_E_NFS;
    EXPECT_EQ(m_ins->GetProtocolType(protocol), Module::PROTOCOL::NFS);
    protocol = NAS_PROTOCOL_TYPE_E_CIFS;
    EXPECT_EQ(m_ins->GetProtocolType(protocol), Module::PROTOCOL::CIFS);
    protocol = "xxx";
    EXPECT_EQ(m_ins->GetProtocolType(protocol), Module::PROTOCOL::PROTOCOL_DEFAULT);  
}

/*
 * 用例名称：GetVendorType
 * 前置条件：无
 * check点：获取vendor类型
 **/
TEST_F(HetroCommonServiceTest, GetVendorType)
{    
    std::string inputVendorStr = NAS_VENDOR_TYPE_STR_HUAWEI_OCEANSTOR;
    EXPECT_EQ(m_ins->GetVendorType(inputVendorStr), Module::STORAGE_ENUM::OCEANSTOR);
    inputVendorStr = NAS_VENDOR_TYPE_STR_HUAWEI_DORADO;
    EXPECT_EQ(m_ins->GetVendorType(inputVendorStr), Module::STORAGE_ENUM::DORADO);
    inputVendorStr = NAS_VENDOR_TYPE_STR_HUAWEI_FUSIONSTOR;
    EXPECT_EQ(m_ins->GetVendorType(inputVendorStr), Module::STORAGE_ENUM::FUSIONSTORAGE);
    inputVendorStr = NAS_VENDOR_TYPE_STR_NETAPP_ONTAP9;
    EXPECT_EQ(m_ins->GetVendorType(inputVendorStr), Module::STORAGE_ENUM::NETAPP);
    inputVendorStr = "xxx";
    EXPECT_EQ(m_ins->GetVendorType(inputVendorStr), Module::STORAGE_ENUM::DEFAULT);
}

/*
 * 用例名称：GetDeviceInfo
 * 前置条件：无
 * check点：获取硬件信息
 **/
TEST_F(HetroCommonServiceTest, GetDeviceInfo)
{   
    MOCKER_CPP(&TEST_Module::HetroCommonServiceImpl::ChangeHostnameToIp)
            .stubs()
            .will(returnValue(-1))
            .then(returnValue(0));
    ProtectedNasHost nasHost;
    ProtectedNasShare nasShare;
    int ret;
    EXPECT_NO_THROW(m_ins->GetDeviceInfo(nasHost, nasShare, ret));
    nasShare.nasShareExt.m_serviceIP = "xxx";
    EXPECT_NO_THROW(m_ins->GetDeviceInfo(nasHost, nasShare, ret));
}